home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Need help with derived class template
- Date: 28 Jan 1996 13:43:58 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan28144358@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4efbcv$ovo@agate.berkeley.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: parsons@vouvray.CS.Berkeley.EDU's message of 28 Jan 1996 08:16:31 GMT
-
- In article <4efbcv$ovo@agate.berkeley.edu> parsons@vouvray.CS.Berkeley.EDU (David C. Parsons) writes:
-
- I am trying to write a class template which is derived from another
- class template, and unfortunately can't seem to get the syntax right.
- I've looked through the FAQ and my C++ books (Stroustrup, Lippman) and
- can't find a discussion of this anywhere.
-
- The base class definition looks like this:
-
- template <class Type>
- class Base { ... }
-
- The compile errors arise from the derived class definition. Here are
- the variations I've tried, and the errors they generate:
-
- 1. template <class Type>
- class Derived : public Base { ... }
-
- ==> parse error before `{'
-
- 2. template <class Type>
- class Derived : public Base<Type> { ... }
-
- ==> base class `Base<double>' has incomplete type
-
- 3. template <class Type>
- class Derived<Type> : public Base<Type> { ... }
-
- ==> Internal compiler error.
- Please submit a full bug report to `bug-g++@prep.ai.mit.edu'.
-
- Any suggestions? Incidentally, the base class by itself works fine,
- and the inheritance works if I remove the templating (i.e. instantiate
- it "by hand" to a particular type).
-
- No. 2 is the correct syntax. For example the following snippet
-
- template<class Type> class Base {};
- template<class Type> class Derived : public Base<Type> {};
- int main() { Derived<int> d; return 0; }
-
- should compile without any problems. So you have left out an
- important detail or your compiler is obsolete.
-
- Enno
-